package com.heiwa.email163;

import com.heiwa.email163.impl.IEmailService;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
@EnableConfigurationProperties(Email163Properties.class)
public class Email163Configuration {
    private String host;
    private String port;
    private String username;
    private String password;
    private String protocol;
    public Email163Configuration(Email163Properties email163Properties) {
        this.port = email163Properties.getPort();
        this.host = email163Properties.getHost();

        this.password = email163Properties.getPassword();
        this.protocol = email163Properties.getProtocol();
        this.username = email163Properties.getUsername();
    }

    @Bean
    public EmailService emailService() {
        return new IEmailService();
    }
    @Bean
    public JavaMailSenderImpl JavaMailSender(){
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
        javaMailSender.setHost(host);
        javaMailSender.setUsername(username);
        javaMailSender.setPassword(password);
        javaMailSender.setProtocol(protocol);
        javaMailSender.setPort(Integer.parseInt(port));
        return javaMailSender;
    }
    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    @Override
    public String toString() {
        return "Email163Configuration{" +
                "host='" + host + '\'' +
                ", port='" + port + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", protocol='" + protocol + '\'' +
                '}';
    }
}
